// $Rev: 130 $

#ifndef SERVER_H
#define SERVER_H

#include <poll.h>
#include <vector>
#include <map>
#include "connection.h"
#include "file_index.h"
#include "constants.h"

// Forward declaration.
class OutgoingConnection;

class Server {
	public:
		Server(int port = DEFAULT_PORT);
		void run();
		FileIndex &get_index();
		bool retrieve_file_info(const std::string md5, const Source *source);
		void add_connection_to(const std::string address,
		                       OutgoingConnection* conn);
		void remove_connection_to(const std::string address);
		~Server();
	private:
		void parse_input();
		void handle_new_connection();
		bool ready;
		int socket;
		std::vector<Connection *> connections;
		std::map<std::string, OutgoingConnection *> outgoing_connections;
		pollfd fds[MAX_CLIENTS];
		FileIndex index;
		// No permitimos operadores de copia o asignacion para esta clase.
		Server(const Server &ic);
		Server &operator=(const Server &ic);
};

#endif
